package main

import (
	"os"
	"fmt"
	"strings"
	nt "./network"
)

const (
	ADDRESS = ":8080"
)

const (
	ADD_DATA = iota + 1
	GET_BLOCK
)

func help() string {
	return `
1. ADD_DATA: ./client add hello, world!
2. GET_BLOCK: ./client get 0
`
}

func main() {
	if len(os.Args) < 3 {
		fmt.Println(help())
	}
	var res = new(nt.Package)
	switch os.Args[1] {
	case "add":
		res = nt.Send(ADDRESS, &nt.Package{
			Option: ADD_DATA,
			Data: strings.Join(os.Args[2:], " "),
		})
	case "get":
		res = nt.Send(ADDRESS, &nt.Package{
			Option: GET_BLOCK,
			Data: os.Args[2],
		})
	}
	if res == nil {
		panic("res == nil")
	}
	fmt.Println("Result:", res.Data)
}
